//
//  FBReportHandle.m
//  UILbrary
//
//  Created by Apple on 2023/3/4.
//  Copyright © 2023 mac. All rights reserved.
//

#import "FBReportHandle.h"


@interface FBReportHandleView : UIView

@property(nonatomic, strong) UIStackView *stackView;
@property(nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIButton *button;
@property(nonatomic, copy) void (^callPhoneBlock)(void);
@end


@implementation FBReportHandleView


//MARK: - system

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self p_configSubviews];
//        [self test];
    }
    return self;
}

//MARK: - test

- (void)test
{
    self.label.backgroundColor = [UIColor systemCyanColor];
    self.button.backgroundColor = [UIColor systemRedColor];
}

//MARK: - action

- (void)reportPhoneNumberAction
{
    NSLog(@"拨打电话");
    if(!self.callPhoneBlock) return;
    self.callPhoneBlock();
}

//MARK: - private

- (void)p_configSubviews
{
    [self addSubview:self.stackView];
    UIView *view_1 = [UIView new];
    [view_1 setContentCompressionResistancePriority:UILayoutPriorityRequired
                                            forAxis:UILayoutConstraintAxisHorizontal];
    [_stackView addArrangedSubview:self.label];
    [_stackView addArrangedSubview:view_1];
    [_stackView addArrangedSubview:self.button];
    
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(120);
    }];
    
    [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self).insets(UIEdgeInsetsMake(0, Space_big, 0, Space_big));
    }];
}

//MARK: - get

- (UIStackView *)stackView
{
    if(!_stackView){
        _stackView = [UIStackView new];
        _stackView.axis = UILayoutConstraintAxisHorizontal;
        _stackView.distribution = UIStackViewDistributionFill;
        _stackView.alignment = UIStackViewAlignmentCenter;
        _stackView.spacing = 10;
    }
    return _stackView;
}

- (UILabel *)label
{
    if(!_label){
        _label = [UILabel new];
        _label.text = @"联系方式";
        _label.textColor = [UIColor blackColor];
        _label.font = [UIFont systemFontOfSize:14.0];
        _label.textAlignment = NSTextAlignmentLeft;
    }
    return _label;
}

- (UIButton *)button
{
    if(!_button){
        _button = [UIButton new];
        [_button setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [_button setTitle:@"400 559 119" forState:UIControlStateNormal];
        [_button addTarget:self action:@selector(reportPhoneNumberAction) forControlEvents:UIControlEventTouchUpInside];
        [_button setTitleColor:[UIColor JX_RedColor] forState:UIControlStateNormal];
    }
    return _button;
}


@end



@interface FBReportHandle()

@property(nonatomic, strong) FBReportHandleView *p_view;

@end


@implementation FBReportHandle

//MARK: - system

- (instancetype)init
{
    self = [super init];
    if(self){
        
    }
    return self;
}

//MARK: - private

- (void)callPhone
{
    NSLog(@"拨打举报电话");
}

//MARK: - get

- (FBReportHandleView *)p_view
{
    if(!_p_view){
        _p_view = [FBReportHandleView new];
        @WeakObj(self);
        _p_view.callPhoneBlock = ^{
            @StrongObj(self)
            [self callPhone];
        };
    }
    return _p_view;
}

- (UIView *)view
{
    return self.p_view;
}

@end
